<template>
	<base-page class="edit-form base-form" style="width: 100vw" title="新增干部" @back="onCancel">
		<view class="main-box">
			<view class="content-box">
				<u-form ref="mobileApplyInfoRef"  :rules="rules" :model="formData" label-width="120px" label-align="left"
					:errorType="['border-bottom', 'message']">
					<u-row gutter="0">
						<u-col :span="12">
							<view class="mt-16">
								<view class="u-cell-group" style="padding: 5px">
									<u-row gutter="0">
										<u-col :span="12">
											<field-input label="姓名" prop="name" v-model="formData.name" type="text"
												:clearable="true" :disabled="false" :required="true"
												:readonly="false" />
										</u-col>
										<u-col :span="12">
											<field-input label="手机号码" prop="phone" v-model="formData.phone" type="text"
												:clearable="true" :disabled="false" :required="true"
												:readonly="false" />
										</u-col>
										<u-col :span="12">
											<field-input label="职务" prop="jobTitle" v-model="formData.jobTitle" type="text"
												:clearable="true" :disabled="false" :required="true"
												:readonly="false" />
										</u-col>

									</u-row>
								</view>
							</view>
						</u-col>
					</u-row>
				</u-form>
			</view>
		</view>
		<view class="menu-box">
			<u-button :custom-style="{width: '100%'}" style="flex-grow: 1; margin-left: 8px" type="primary"
				size="medium" @click="onAddClick()">
				提交
			</u-button>
		</view>
		<u-modal v-model="show" :content="content" show-cancel-button  @cancel="onCancel()" @confirm="addContinue()" confirm-text="继续添加" cancel-text='返回'></u-modal>

	</base-page>
</template>

<script>
	import {
		showMessage,
	} from '@/utils';
	import {
		CourseInfoController,
	} from '@/api';
	import projectConfig from '@/core/config'
	export default {
		name: 'mobileApplyInfo',

		data() {
			return {
				show: false,
				content: '',
				formData: {
					// id
					id: undefined,
					// 班级id
					classId: undefined,
					// 姓名
					name: undefined,

					officerId: undefined,
					// 手机号码
					phone: undefined,

				},
				classIdWidget: [],
				ganbuWidget: [],
				rules: {
					'name': [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur',
						transform: (value) => String(value)
					}],
					'phone': [{
						required: true,
						message: '请输入手机号码',
						trigger: 'blur',
						transform: (value) => String(value)
					}],

					'jobTitle': [{
						required: true,
						message: '请填写职务',
						trigger: 'blur',
						transform: (value) => String(value)
					}],

				},
				fileList: []

			}
		},
		computed() {},
		methods: {
			addContinue(){
				this.formData={
					name:'',
					officerId:'',
					phone:'',
				}
				
			},
			onCancel() {
				uni.navigateBack();
			},
			
			changeGan(val, val2) {
				this.formData.officerId = val2.id
				this.formData.jobTitle = val2.jobTitle
				this.formData.name = val2.name
				this.formData.phone = val2.phone
			},
			/**
			 * 提交
			 */
			onAddClick() {

				this.$refs.mobileApplyInfoRef.validate((valid) => {

					if (!valid) return;

					let params = {
						// studentInfoDto: {
						// 	userId: uni.getStorageSync('userId'),
						// 	name: this.formData.name,
						// 	classId: this.formData.classId,
						// 	jobTitle: this.formData.jobTitle,
						// 	officerId: this.formData.officerId,
						// 	phone: this.formData.phone,
						// }
						officerInfoDto: this.formData
					};

					CourseInfoController.officerInfoAdd(this, params)
							.then((res) => {
								this.show = true;
						if (res) {
							this.content="新增成功"
						}else{
							this.content="新增失败"
						}
								// if (res) {
								// 	this.$u.toast('新增成功');
								// 	// uni.navigateTo({
								// 	// 	url: "/views/school/cadreList"
								// 	// })
								// } else {
								// 	this.$u.toast('新增失败');
								// }

							})
							.catch((e) => {});
				});
			},

		},
		computed: {

		},
		mounted() {
		}
	};
</script>

<style scoped></style>